<!-- 查询区 -->
<div id="searchContainer"></div>
<div class="row1 up_row">
    <div class="data_container">
        <!-- 按钮区 -->
        <div id="buttonsDiv">
        </div>
        <!-- 数据列表区 -->
        <div id="contentDiv" class="content_div"></div>
    </div>
</div>
<script src="/public/js/timeago/timeago.min.js"></script>
<script>
$(function() {
    // 加载查询区
    var searchBar = new SearchBar({
        containerId: "searchContainer",
        //textPlaceholder: '查询条件：模块名、升级包名、升级内容',
        queryList: [
            { title: "开发者", key: "author", url: "/select/getSvnUser?key=author", forSort: 10 },
            { title: "日志范围", key: "date_range", data: { key: "date_range", datas: [{ code: "0", name: "今天" }, { code: "-1", name: "昨天" }, { code: "-2", name: "前天" }] } }
        ],
        queryFunc: function() { load(); }
    });
    searchBar.render();

    // 加载表格
    var workGrid = new WorkGrid({
        url: '/svnLog/query',
        searchBar: searchBar,
        columns: [
            { display: "Revison", property: "svn_revision", sort: "svn_revision", width: "10%" },
            { display: "Author", property: "svn_author", sort: "svn_author", width: "10%" },
            { display: "Author_name", property: "svn_author_name", sort: "svn_author_name", width: "12%" },
            { display: "Date", property: "svn_date", sort: "svn_date", width: "16%" },
            {
                display: "Message",
                property: "svn_message",
                sort: "svn_message",
                view: function(col) {
                    return noHighlight(col.svn_message);
                }
            },
            { display: "File Count", property: "c", sort: "c", width: "9%" },
            {
                display: "操作",
                width: "8%",
                view: function(col) {
                    var view = '';
                    view += '<button type="button" data-svn_revision="' + col.svn_revision + '" data-action="info" class="am-btn am-btn-secondary am-btn-mini am-radius">查看</button>';
                    return view;
                }
            }
        ],
        loadAfterListener: function() {
            // 格式化创建时间的格式
            timeago().render(document.querySelectorAll('.need_to_be_rendered'), 'zh_CN');

            // 绑定提示
            $('[role="tip"]').mouseover(function() {
                var _this = $(this);
                _this.justToolsTip({
                    animation: "moveInTop",
                    contents: _this.attr('tip') || '',
                    gravity: 'top'
                });
            });

            // 查看升级包
            $('#contentDiv [data-action="info"]').click(function() {
                var svn_revision = $(this).attr('data-svn_revision');
                zeroModal.show({
                    content: '<div id="svnPathInfoDiv"></div><form id="svnPathInfoForm" style="display:none;"><input type="hidden" name="svn_revision" value="' + svn_revision + '" /></form>',
                    title: '查看升级包',
                    width: '70%',
                    height: '70%',
                    onComplete: function() {
                        var workGrid1 = new WorkGrid({
                            url: '/svnLog/querySvnPath',
                            containerId: 'svnPathInfoDiv',
                            formId: 'svnPathInfoForm',
                            columns: [
                                { display: "Type", property: "svn_type", width: "14%" },
                                { display: "Path", property: "svn_path" }
                            ]
                        });
                        workGrid1.render();
                    }
                });
            });
        }
    });
    workGrid.render();

    // 查询
    function load(params) {
        workGrid.load(1, params);
    }

    function noHighlight(str) {
        if (str === undefined || str === null || str === '') {
            return str;
        }

        var re = /#\d*\s/g;
        var allStr;

        var keywords = [];
        while ((allStr = re.exec(str)) !== null) {
            keywords.push(allStr[0]);
        }
        for (var i = 0; i < keywords.length; i++) {
            str = str.replace(keywords[i], '<font color="#EF971C">' + keywords[i] + '</font>');
        }
        return str;
    }
});
</script>